package com.kjsdfgk.hjmdsf.video.mvp.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.kjsdfgk.hjmdsf.app.utils.SharedPrefsUtils;
import com.kjsdfgk.hjmdsf.live.mvp.bean.PingtaiBean;
import com.kjsdfgk.hjmdsf.charge.mvp.ui.activity.MemberChargeActivity;
import com.kjsdfgk.hjmdsf.video.di.component.DaggerVideoComponent;
import com.kjsdfgk.hjmdsf.video.mvp.bean.ZhuboBean;
import com.kjsdfgk.hjmdsf.video.mvp.contract.VideoContract;
import com.kjsdfgk.hjmdsf.video.mvp.presenter.VideoPresenter;

import com.lksdkjs.live.R;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;


import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 04/10/2020 11:50
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class VideoActivity extends BaseActivity<VideoPresenter> implements VideoContract.View {

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerVideoComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_video; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;
    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        PingtaiBean pingtaiBean = (PingtaiBean) getIntent().getSerializableExtra("bean" );
        setTitle(pingtaiBean.getTitle());

        mPresenter.getZhuboJson(pingtaiBean.getAddress());

        final GridLayoutManager mLayoutManager = new GridLayoutManager(this, 2);
        mRecyclerView.setLayoutManager(mLayoutManager);

        ArmsUtils.configRecyclerView(mRecyclerView, mLayoutManager);
    }

    @Override
    public void showLoading(String key) {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public boolean isCancel() {
        return false;
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }
    VideoAdapter mAdapter;
    @Override
    public void showZhubo(List<ZhuboBean> zhubo) {
        mRecyclerView.setAdapter(mAdapter = new VideoAdapter(zhubo));
    }

    @Override
    public void showMemberDlg() {
        QMUIDialog.MessageDialogBuilder builder = new QMUIDialog.MessageDialogBuilder(this);
        builder.setTitle("系统提示");
        builder.setMessage("您的会员已过期 ，请续费");
        builder.addAction("     卡密购买     ", (dialog, index) -> {

            String url = SharedPrefsUtils.getString("kamiUrl","");
            if (!TextUtils.isEmpty(url)){
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                finish();
            }else {
                showMessage("系统错误 ，请稍后在试");
            }

        });
        builder.addAction("     卡密充值     ", (dialog, index) -> {
            Intent intent = new Intent(getBaseContext() , MemberChargeActivity.class);
            startActivity(intent);
            finish();
        });


        builder.show();



//        AlertDialog.Builder builder = new AlertDialog.Builder( this);
//        builder.setTitle("聚合直播");
//        builder.setMessage("您的会员已过期 ，请续费");
//        builder.setCancelable(true);            //点击对话框以外的区域是否让对话框消失
//
//        //设置正面按钮
//        builder.setPositiveButton("卡密购买", new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
//                String url = "https://www.baidu.com/";
//                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
//                startActivity(intent);
//                finish();
//            }
//        });
//        //设置反面按钮
//        builder.setNegativeButton("卡密充值", new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
//                Intent intent = new Intent(getBaseContext() , MemberChargeActivity.class);
//                startActivity(intent);
//                finish();
//            }
//        });
        //设置中立按钮


//
//        AlertDialog dialog = builder.create();      //创建AlertDialog对象
//
//        builder.setCancelable(false);
//        builder.show();
//        dialog.show();
    }
}
